your personal website on atproto - mirror blento.app
at fix-cached-posts 47 lines 1.2 kB view raw
1import { createCache } from '$lib/cache'; 2import { error, json } from '@sveltejs/kit'; 3import { getActor } from '$lib/actor'; 4import { listRecords } from '$lib/atproto/methods.js'; 5import type { EventData } from '$lib/cards/social/EventCard'; 6import type { Did } from '@atcute/lexicons'; 7 8export async function GET({ params, platform, request }) { 9 const cache = createCache(platform); 10 if (!cache) return json('no cache'); 11 12 const did = await getActor({ request, paramActor: params.actor, platform, blockBoth: false }); 13 14 if (!did) { 15 throw error(404, 'Not found'); 16 } 17 18 // Delete stale caches 19 await Promise.all([cache.delete('events', did), cache.delete('ical', `${did}:calendar`)]).catch( 20 () => {} 21 ); 22 23 // Re-fetch and cache 24 const [records, hostProfile] = await Promise.all([ 25 listRecords({ 26 did: did as Did, 27 collection: 'community.lexicon.calendar.event', 28 limit: 100 29 }), 30 cache.getProfile(did as Did).catch(() => null) 31 ]); 32 33 const events = records.map((r) => ({ 34 ...(r.value as EventData), 35 rkey: r.uri.split('/').pop() as string 36 })); 37 38 const result = { 39 events, 40 did, 41 hostProfile: hostProfile ?? null 42 }; 43 44 await cache.putJSON('events', did, result).catch(() => {}); 45 46 return json(result); 47}